#! /bin/sh

if [ "$#" -lt 2 ]; then
    exit "not enought args"
fi

if ! hash kubectl 2>/dev/null;then
    exit "can't find kubectl"
fi


kubeconfig=$1
action=$2
root_dir=`(cd $(dirname $0);pwd)`

Set() {
    guid=$1 

    sed -e "s/AGENT_GUID/${guid}/g" $root_dir/prometheus/rules/rules.yaml > $root_dir/prometheus/prometheus-prometheusRule.yaml

    kubectl --kubeconfig $kubeconfig apply --server-side -f $root_dir/prometheus/setup &&

    kubectl --kubeconfig $kubeconfig apply -f $root_dir/prometheus/transfer &&

    kubectl --kubeconfig $kubeconfig apply -f $root_dir/prometheus
}

Clear() {
    kubectl --kubeconfig $kubeconfig delete -f $root_dir/prometheus &&

    kubectl --kubeconfig $kubeconfig delete -f $root_dir/prometheus/transfer &&

    kubectl --kubeconfig $kubeconfig delete -f $root_dir/prometheus/setup 
}

if [ "$action" = "set" ];then

if [ "$#" -ne 3 ]; then
    exit "not enought args"
fi
Set $3

else
Clear
fi








